From a226de765875e5bc78f6793c4f6c2dbcac4fce0f Mon Sep 17 00:00:00 2001 From: Jeroen van der Heijden Date: Sat, 6 Oct 2018 10:49:55 +0200 Subject: [PATCH] Added colors --- itest/testing/__init__.py | 51 +------------------------------- itest/testing/args.py | 25 +++++++++++++++- itest/testing/color.py | 22 ++++++++++++++ itest/testing/spinner.py | 21 +++++++++++++ itest/testing/task.py | 36 ++++++++++++++++++++++ test/test_version/test_version.c | 6 ++-- 6 files changed, 106 insertions(+), 55 deletions(-) create mode 100644 itest/testing/color.py create mode 100644 itest/testing/spinner.py create mode 100644 itest/testing/task.py diff --git a/itest/testing/__init__.py b/itest/testing/__init__.py index 282c8ff6..9ce56c32 100644 --- a/itest/testing/__init__.py +++ b/itest/testing/__init__.py @@ -1,7 +1,5 @@ -import sys import asyncio import logging -import time from .client import Client from .client import InsertError from .client import PoolError @@ -19,54 +17,7 @@ from .testbase import TestBase from .series import Series from .pipe_client import PipeClient as SiriDBAsyncUnixConnection from .args import parse_args - -SPINNER1 = \ - ('▁', '▂', '▃', '▄', '▅', '▆', '▇', '█', '▇', '▆', '▅', '▄', '▃', '▁') -SPINNER2 = \ - ('⠁', '⠂', '⠄', '⡀', '⢀', '⠠', '⠐', '⠈') -SPINNER3 = \ - ('◐', '◓', '◑', '◒') - - -class Spinner(): - - def __init__(self, charset=SPINNER3): - self._idx = 0 - self._charset = charset - self._len = len(charset) - - @property - def next(self): - char = self._charset[self._idx] - self._idx += 1 - self._idx %= self._len - return char - - -class Task(): - def __init__(self, title): - self.running = True - self.task = asyncio.ensure_future(self.process()) - self.success = False - self.title = title - self.start = time.time() - - def stop(self, success): - self.running = False - self.success = success - self.duration = time.time() - self.start - - async def process(self): - spinner = Spinner() - while self.running: - sys.stdout.write(f'{self.title:.<76}{spinner.next}\r') - sys.stdout.flush() - await asyncio.sleep(0.2) - - if self.success: - print(f'{self.title:.<76}OK ({self.duration:.2f} seconds)') - else: - print(f'{self.title:.<76}FAILED ({self.duration:.2f} seconds)') +from .task import Task async def _run_test(test, loglevel): diff --git a/itest/testing/args.py b/itest/testing/args.py index 3a7506a2..da7171de 100644 --- a/itest/testing/args.py +++ b/itest/testing/args.py @@ -1,5 +1,18 @@ +import os +import subprocess import argparse from .server import Server +from .color import Color + + +def is_valgrind_installed(): + with open(os.devnull, 'w') as fnull: + try: + subprocess.call(['valgrind'], stdout=fnull, stderr=fnull) + except OSError as e: + if e.errno == os.errno.ENOENT: + return False + return True def parse_args(): @@ -37,7 +50,17 @@ def parse_args(): args = parser.parse_args() - Server.MEM_CHECK = args.mem_check + has_valgrind = is_valgrind_installed() + + print("Test using valgrind for memory errors and leaks: ", end='') + if args.mem_check and not has_valgrind: + print(Color.warning('disabled (!! valgrind not found !!)')) + elif not args.mem_check: + print(Color.warning('disabled')) + else: + print(Color.success('enabled')) + + Server.MEM_CHECK = args.mem_check and has_valgrind Server.HOLD_TERM = args.keep Server.TERMINAL = args.terminal Server.BUILDTYPE = args.build diff --git a/itest/testing/color.py b/itest/testing/color.py new file mode 100644 index 00000000..ff28fe21 --- /dev/null +++ b/itest/testing/color.py @@ -0,0 +1,22 @@ + +NORMAL = '\x1B[0m' +RED = '\x1B[31m' +GREEN = '\x1B[32m' +YELLOW = '\x1B[33m' + + +class Color: + + @staticmethod + def success(text): + return f'{GREEN}{text}{NORMAL}' + + @staticmethod + def warning(text): + return f'{YELLOW}{text}{NORMAL}' + + @staticmethod + def error(text): + return f'{RED}{text}{NORMAL}' + + diff --git a/itest/testing/spinner.py b/itest/testing/spinner.py new file mode 100644 index 00000000..bf21fcc1 --- /dev/null +++ b/itest/testing/spinner.py @@ -0,0 +1,21 @@ +SPINNER1 = \ + ('▁', '▂', '▃', '▄', '▅', '▆', '▇', '█', '▇', '▆', '▅', '▄', '▃', '▁') +SPINNER2 = \ + ('⠁', '⠂', '⠄', '⡀', '⢀', '⠠', '⠐', '⠈') +SPINNER3 = \ + ('◐', '◓', '◑', '◒') + + +class Spinner(): + + def __init__(self, charset=SPINNER3): + self._idx = 0 + self._charset = charset + self._len = len(charset) + + @property + def next(self): + char = self._charset[self._idx] + self._idx += 1 + self._idx %= self._len + return char diff --git a/itest/testing/task.py b/itest/testing/task.py new file mode 100644 index 00000000..7f26bd63 --- /dev/null +++ b/itest/testing/task.py @@ -0,0 +1,36 @@ +import sys +import time +import asyncio +from .spinner import Spinner +from .color import Color + + +class Task(): + def __init__(self, title): + self.running = True + self.task = asyncio.ensure_future(self.process()) + self.success = False + self.title = title + self.start = time.time() + + def stop(self, success): + self.running = False + self.success = success + self.duration = time.time() - self.start + + async def process(self): + spinner = Spinner() + while self.running: + sys.stdout.write(f'{self.title:.<76}{spinner.next}\r') + sys.stdout.flush() + await asyncio.sleep(0.2) + + if self.success: + print( + f'{self.title:.<76}' + f'{Color.success("OK")} ({self.duration:.2f} seconds)') + else: + print( + f'{self.title:.<76}' + f'{Color.error("FAILED")} ({self.duration:.2f} seconds)') + diff --git a/test/test_version/test_version.c b/test/test_version/test_version.c index 95569e25..bfae981a 100644 --- a/test/test_version/test_version.c +++ b/test/test_version/test_version.c @@ -1,9 +1,9 @@ +#include +#include #include "../test.h" #include -#include -#include int old_version_cmp(const char * version_a, const char * version_b) { @@ -17,8 +17,6 @@ int old_version_cmp(const char * version_a, const char * version_b) a = strtol(str_a, &str_a, 10); b = strtol(str_b, &str_b, 10); - printf("%ld - %ld\n", a, b); - if (a != b) { return a - b; -- 2.30.2